﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// Pour en savoir plus sur le modèle d'élément Contrôle utilisateur, consultez la page http://go.microsoft.com/fwlink/?LinkId=234236

namespace BlipSansBlop
{
    public sealed partial class BoutonA : UserControl
    {
        public static BoutonA Instance { get; set; }
        // Pour en faire un singleton et acceder au seul joystick via Joystick.Instance

        /// <summary>
        /// Booléen gérant aussi l'affichage du bouton
        /// </summary>
        private static Boolean estAppuie;
        public static Boolean EstAppuie
        {
            get { return BoutonA.estAppuie; }
            set {
                BoutonA.estAppuie = value;
                if (BoutonA.estAppuie) BoutonA.Instance.up.Visibility = Visibility.Collapsed;
                else BoutonA.Instance.up.Visibility = Visibility.Visible;
            }
        }
        private static Boolean oPressed;
        public static Boolean OPressed
        {
            get { return BoutonA.oPressed; }
            set 
            { 
                BoutonA.oPressed = value; 
                BoutonA.EstAppuie = value; 
                Joystick.KeyPressed = (Joystick.ZPressed || Joystick.SPressed || Joystick.QPressed || Joystick.DPressed || BoutonA.OPressed || BoutonB.KPressed); 
            }
        }

        public BoutonA()
        {
            this.InitializeComponent();
            BoutonA.Instance = this;
            BoutonA.EstAppuie = false;
            BoutonA.Instance.grid.ManipulationMode =
                ManipulationModes.None;
        }
        
        #region Gestion des évènements tactiles et de curseurs
        private void grid_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            BoutonA.EstAppuie = true;
            DebugControl.Update();
        }

        private void grid_Holding(object sender, HoldingRoutedEventArgs e)
        {
            BoutonA.EstAppuie = true;
            DebugControl.Update();
        }

        private void grid_DragLeave(object sender, DragEventArgs e)
        {
            BoutonA.EstAppuie = false;
            DebugControl.Update();
        }

        private void grid_DragEnter(object sender, DragEventArgs e)
        {
            BoutonA.EstAppuie = true;
            DebugControl.Update();
        }

        private void grid_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            BoutonA.EstAppuie = false;
            DebugControl.Update();
        }
        #endregion
        
    }
}
